package cn.iocoder.yudao.module.reading.controller.app.assignment.vo;

import cn.iocoder.yudao.module.reading.framework.vo.BaseUrlConvertVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import cn.hutool.core.util.StrUtil;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 班级作业信息 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 班级作业信息 Response VO")
@Data
@EqualsAndHashCode(callSuper = false)
public class AssignmentRespVO extends BaseUrlConvertVO {

    @Schema(description = "作业ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long id;

    @Schema(description = "作业标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "07月03日作业")
    private String title;

    @Schema(description = "班级ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer classId;

    @Schema(description = "创建者ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer creatorId;

    @Schema(description = "截止日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2025-01-03")
    private LocalDate assignmentDate;

    @Schema(description = "完成要求类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "audio")
    private String requirementType;

    @Schema(description = "作业描述", example = "请完成小猪佩奇前两个故事的配音练习")
    private String description;

    @Schema(description = "绘本总数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    private Integer totalBooks;

    @Schema(description = "已完成人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Integer completedCount;

    @Schema(description = "班级总人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    private Integer totalMembers;

    @Schema(description = "是否为跨班级作业", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
    private Boolean isMultiClass;

    @Schema(description = "作业包含的绘本列表")
    private List<AssignmentBookRespVO> books;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2025-01-03T08:00:00")
    private LocalDateTime createTime;

    @Schema(description = "作业绘本信息")
    @Data
    public static class AssignmentBookRespVO {
        @Schema(description = "绘本ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        private Long id;

        @Schema(description = "绘本标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "Muddy Puddles")
        private String title;

        @Schema(description = "绘本封面", example = "/static/books/peppa_01.jpg")
        private String cover;

        @Schema(description = "排序顺序", example = "1")
        private Integer sortOrder;

        @Schema(description = "完成情况", example = "true")
        private Boolean isCompleted;
    }

    @Schema(description = "绘本信息")
    @Data
    public static class BookInfo {
        @Schema(description = "绘本ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        private Long id;

        @Schema(description = "绘本标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "Muddy Puddles")
        private String title;

        @Schema(description = "绘本封面", example = "/static/books/peppa_01.jpg")
        private String cover;

        @Schema(description = "排序顺序", example = "1")
        private Integer sortOrder;
    }

    /**
     * 转换URL为完整路径
     * 这个方法用于将相对路径转换为完整URL
     */
    @Override
    public void convertUrls() {
        // 转换绘本列表中的封面URL
        if (this.books != null) {
            this.books.forEach(book -> {
                book.setCover(convertUrl(book.getCover()));
            });
        }
    }

}
